package com.cy.ppj.web.admin.finance;

import com.cy.ppj.model.enums.WithholdStatus;
import com.cy.ppj.model.vo.admin.order.OrderWithholdAdminStatisticsVO;
import com.cy.ppj.service.order.WithholdRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cy.ppj.model.PageBean;
import com.cy.ppj.model.Result;
import com.cy.ppj.model.query.order.OrderWithholdAdminQuery;
import com.cy.ppj.model.vo.admin.order.OrderWithholdAdminVO;
import com.cy.ppj.service.order.OrderService;
import com.cy.ppj.service.order.WithholdService;
import com.cy.ppj.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 后台-代扣处理
 * @author: tanyilin
 * @create: 2018年8月4日 下午5:21:58
 */
@Slf4j
@RestController
@RequestMapping("/admin/withhold")
@Api(tags = "后台-代扣处理")
public class AdminWithholdController extends BaseController{

	@Autowired
	private OrderService orderService;
	@Autowired
	private WithholdService withholdService;
	@Autowired
	private WithholdRecordService withholdRecordService;
	
	@ApiOperation("代扣列表")
	@GetMapping("/list")
	public PageBean<OrderWithholdAdminVO> list(OrderWithholdAdminQuery query) {
		query.setType(1);
		return orderService.queryOrderWithholdAdminList(query);
	}
	
	@ApiOperation("/执行代扣")
	@PostMapping("/do/withhold")
	public Result doWithhold(@ApiParam(value = "订单ID", example = "0", required = true) @RequestParam Long orderId) {
		return withholdService.withholding(orderId, this.getManager().getManagerId());
	}

	@ApiOperation("代扣统计")
	@GetMapping("/statistics")
	public Result statistics() {
		List<OrderWithholdAdminStatisticsVO> list = withholdRecordService.orderWithholdAdminStatisticsInCache();
		return ok("", list);
	}

	@ApiOperation("手动设置代扣状态")
	@GetMapping("/update/{id}")
	public Result update(@PathVariable Long id, @RequestParam WithholdStatus status) {
		withholdRecordService.updateStatus(id, status);
		return ok();
	}
}
